﻿using Newtonsoft.Json;
using OConf.NetCore.Common;
using OConf.NetCore.Model;

namespace OConf.NetCore
{
    public static class Cache
    {
        /// <summary>
        /// 配置文件保存文件夹路径
        /// </summary>
        public static string saveDicPath { get; } = Path.Combine(Environment.CurrentDirectory, "configfile");

        /// <summary>
        /// 项目配置文件名称
        /// </summary>
        public static string projectConfigFileName { get; } = "setting";

        /// <summary>
        /// 获取项目配置文件信息
        /// </summary>
        /// <returns></returns>
        public static ProjectConfigModel GetProjectConfig()
        {
            string projectConfigPath = Path.Combine(saveDicPath, $"{projectConfigFileName}.json");
            if (!File.Exists(projectConfigPath))
            {
                return null;
            }

            string projectConfigJson = FileCore.ReadFile(projectConfigPath);

            try
            {
                return JsonConvert.DeserializeObject<ProjectConfigModel>(projectConfigJson);
            }
            catch
            {
                return null;
            }
        }
    }
}
